
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>SpringBoot+UniApp实现WebSocket通讯 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>SpringBoot+UniApp实现WebSocket通讯 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">为什么标准的HTTP协议不适合用于需要服务端主动推送信息的双向通讯场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">HTTP协议是一种单向网络协议，通信只能由客户端发起。如果服务器有状态变化，无法主动通知客户端，客户端必须通过轮询来获取最新数据，这在服务端数据无变化时会造成资源浪费。</div>
          </div>
          <div class="card-source">来源: 引言</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">WebSocket协议的核心特性是什么？它如何解决HTTP协议在实时通信中的缺陷？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">WebSocket是一种在单个TCP连接上进行全双工通讯的协议。它允许服务端主动向客户端推送数据。浏览器和服务器只需完成一次握手，即可创建持久性连接进行双向数据传输，从而节省服务器资源和带宽，实现更实时的通讯。</div>
          </div>
          <div class="card-source">来源: WebSocket简介</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">请简述短连接和长连接在工作方式上的主要区别。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">短连接是客户端和服务器每进行一次HTTP操作就建立一次连接，任务结束立即中断。长连接则是在一个网页打开后，用于传输HTTP数据的TCP连接不会关闭，客户端再次访问该服务器时会继续使用已建立的连接。</div>
          </div>
          <div class="card-source">来源: 长连接短连接</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在基于`netty-websocket-spring-boot-starter`的WebSocket服务器实现中，`@ServerEndpoint`注解的作用是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">该注解用于将一个类注册为WebSocket端点。当`ServerEndpointExporter` bean被声明后，它会扫描带有此注解的类。端点的所有配置项（如路径`path`、主机`host`、端口`port`等）都在该注解的属性中定义。</div>
          </div>
          <div class="card-source">来源: WebSocket注解说明</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在WebSocket的生命周期中，`@OnOpen`和`@OnClose`注解分别在何时被触发？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`@OnOpen`注解的方法在新的WebSocket连接完成时被回调。`@OnClose`注解的方法在WebSocket连接关闭时被回调。</div>
          </div>
          <div class="card-source">来源: WebSocket注解说明</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">文档中介绍了哪两种处理WebSocket消息的注解，它们分别对应什么类型的消息？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中介绍了`@OnMessage`和`@OnBinary`两个注解。`@OnMessage`用于接收字符串消息，其方法可注入`Session`和`String`类型的参数。`@OnBinary`用于接收二进制消息，其方法可注入`Session`和`byte[]`类型的参数。</div>
          </div>
          <div class="card-source">来源: WebSocket注解说明</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">在实现聊天功能时，文档提出的`SessionManager`是如何管理所有在线用户的会话的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`SessionManager`内部使用一个`ConcurrentHashMap`来存储在线用户的会话。当用户连接时（@OnOpen），会将其唯一标识（如token）和对应的`Session`对象添加到Map中；当用户断开连接时（@OnClose），会从Map中移除其会话。</div>
          </div>
          <div class="card-source">来源: 实现聊天功能</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">当需要通过WebSocket传递二进制数据（如图片）时，文档中推荐的处理方法是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">推荐的方法是先将二进制数组（byteArray）通过Base64编码转换成一个字符串进行传递。服务端收到该字符串后，再进行Base64解码，将其还原为byteArray，然后写入到流中进行处理。</div>
          </div>
          <div class="card-source">来源: WebSocket传递二进制数据</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在WebSocket连接建立过程中，`@BeforeHandshake`注解的作用是什么？它通常在哪个阶段被回调？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`@BeforeHandshake`注解用于在WebSocket握手完成之前进行一些操作，例如身份验证或保存客户端信息到session中。当有新的连接请求进入时，该注解对应的方法会被回调。</div>
          </div>
          <div class="card-source">来源: WebSocket注解说明</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
